<include file="Public/header" />
<style type="text/css">
    .inner .mall-manage{min-height:680px;}
    .diy-menu .btn-success{background-color:#009997;border-color:#009997;}
    .diy-menu .preview a:hover{background-color:#009997;}
</style>
<div class="comm-top">
	<h4 style="margin-bottom:0">账号信息
        <span style="font-size:12px;color:#aaa;font-weight:normal;">（最多创建3个一级菜单，每个一级菜单下最多可以创建5个二级菜单。菜单发布24小时后生效。您也可以先取消关注，再重新关注即可马上看到菜单）</span>
    </h4>
	<div class="add_page_top"></div>
</div>
<div class="diy-menu" style="margin:0;margin-top:20px;margin-left:50px;">
    <h3>底部菜单管理</h3>
    <div class="preview">
        <div class='col c1' m_nu='1'>
            <a href='javascript:;' menu_id='1' m_id='0'>+</a>
            <volist name="first" id="vo">
                <a class='alpha' menu_id='1' href='javascript:;' m_id=<{$vo['id']}>><{$vo.title}></a>
            </volist>
        </div>
        <div class='col c2' m_nu='2'>
            <a href='javascript:;' menu_id='2' m_id='0'>+</a>
            <volist name="second" id="vo">
                <a class='alpha' menu_id='2' href='javascript:;' m_id=<{$vo['id']}>><{$vo.title}></a>
            </volist>
        </div>
        <div class='col c3' m_nu='3'>
            <a href='javascript:;' menu_id='3' m_id='0'>+</a>
            <volist name="third" id="vo">
                <a class='alpha' menu_id='3' href='javascript:;' m_id=<{$vo['id']}>><{$vo.title}></a>
            </volist>
        </div>
    </div>
    <div class="opt">
        <div class="null">
            点击左侧[<span class="c-green">+</span>]号添加微信底部菜单
        </div>
        <div class="inner" style="display:none;">
            <p class="c-gray fz12px">请选择订阅者点击菜单后，公众号做出相应动作</p>
            <form class="form-horizontal user-form form-menu" id="menu_f" role="form">
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单名称</label>
                    <div class="col-sm-6">
                        <input type="text" name="title" class="form-control" maxlength="50"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">消息类型</label>
                    <div class="col-sm-6">
                        <select id="uniqueSelect" name="type" class="form-control" onchange="sm_type(this.value)">
                            <option value="view" class="m_view">链接地址</option>
                            <option value="click" class="m_click">关键词绑定</option>
                        </select>
                    </div>
                </div>
                <div class="form-group m_key1">
                    <label class="col-sm-3 control-label" id='unqi'>链接地址</label>
                    <div class="col-sm-9">
                        <input type="url" name="url" class="form-control" maxlength="255"/>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-9">
                        <input type="hidden" name="id" value="" />
                        <input type="hidden" name="position" value="" />
                        <button type='button' id="saveBtn" name="save" class="btn btn-success">保存</button>&nbsp;&nbsp;&nbsp;
                        <button type='button' name="delete_menu" class="btn btn-success">删除</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <a class="btn btn-large btn-success" href="javascript:;" name="create_menu">发布菜单</a>
</div>
<script>
    $(function(){
        $(".preview").find("a").click(function(){
            $("#menu_f").find("input").val('');
            $("[name=position]").val($(this).attr("menu_id"));
            $("[name=id]").val($(this).attr("m_id"));
            if($(this).attr("m_id")==0){
                $("[name=delete_menu]").hide();
            }else{
                $("[name=delete_menu]").show();
                $.ajax({
                    type: "POST",
                    url: "<{:U('editMenu')}>",
                    data:{id:$("[name=id]").val()},
                    success:function(data){
                        if(data.status ==1){
                            $("[name=title]").val(data.info.title);
                            $("#uniqueSelect").val(data.info.type);
                            $("[name=url]").val(data.info.url);
                            (data.info.type == 'click') ? $('#unqi').html('绑定规则') : $('#unqi').html('链接地址');
                        }
                    }
                });
            }
            $(".null").hide();
            $(".inner").show();
        });

        $("[name=save]").click(function(){
            $.ajax({
                type: "POST",
                url: "<{:U('saveMenu')}>",
                data:{id:$("[name=id]").val(),type:$("#uniqueSelect").val(),title:$("[name=title]").val(),url:$("[name=url]").val(),position:$("[name=position]").val()},
                success:function(data){
                    layer.alert(data.info);
                    if(data.status ==1){
                        setTimeout("location.reload()",1200);
                    }
                }
            });
        });

        $("[name=create_menu]").click(function(){
            var layerLoad = layer.load(1,{shade: [0.1,'#fff']});
            $.ajax({
                type: "POST",
                url: "<{:U('createMenu')}>",
                success:function(data){
                    layer.close(layerLoad);
                    layer.alert(data.info);
                }
            });
        });

        $("[name=delete_menu]").click(function(){
            if(confirm("是否确认删除")){
                $.ajax({
                    type: "POST",
                    url: "<{:U('deleteMenu')}>",
                    data:{id:$("[name=id]").val()},
                    success:function(data){
                        layer.alert(data.info);
                        if(data.status ==1){
                            setTimeout("location.reload()",1200);
                        }
                    }
                });
            }
        });
    });

    function sm_type(a){
		if(a=='view'){
			$('#unqi').html('链接地址');
		}else{
			$('#unqi').html('绑定规则');
		}
	}
</script>
<include file="Public/footer"/>